#include "common/be_rand.h"
#include "be_color.h"

BeColor::BeColor()
{
	r = 0.0f;
	g = 0.0f;
	b = 0.0f;
	a = 0.0f;
}

BeColor::BeColor( float nr, float ng, float nb, float na )
{
	r = nr;
	g = ng;
	b = nb;
	a = na;
}

BeColor BeColor::randomBeColorRGB()
{
	BeColor c;
	c.r = (float)BeRand::Instance()->get( 1,100 ) / 100.0f;
	c.g = (float)BeRand::Instance()->get( 1,100 ) / 100.0f;
	c.b = (float)BeRand::Instance()->get( 1,100 ) / 100.0f;
	c.a = 0.0f;
	
	return c;
}

void BeColor::normalize(BeColor* c)
{
	float highest = c->r;
	if ( c->g > highest )
		highest = c->g;
	if ( c->b > highest )
		highest = c->b;
	if ( c->a > highest )
		highest = c->a;

	c->r /= highest;
	c->g /= highest;
	c->b /= highest;
	c->a /= highest;
}

BeColor BeColor::getNormalized()
{
	float highest = r;
	if ( g > highest )
		highest = g;
	if ( b > highest )
		highest = b;
	if ( a > highest )
		highest = a;

	BeColor c;
	c.r = r/highest;
	c.g = g/highest;
	c.b = b/highest;
	c.a = a/highest;
	
	return c;
}

void BeColor::normalize()
{
	float highest = r;
	if ( g > highest )
		highest = g;
	if ( b > highest )
		highest = b;
	if ( a > highest )
		highest = a;

	r /= highest;
	g /= highest;
	b /= highest;
	a /= highest;
}

BeColor& BeColor::operator=(const BeColor& other)
{
	r = other.r;
	g = other.g;
	b = other.b;
	a = other.a;
	return (*this);
}

BeColor::~BeColor()
{
}


